<style>
    /* 用户信息 */
    .user-info-head {
        width: 110px;
        height: 110px;
        line-height: 110px;
        position: relative;
        display: inline-block;
        border: 2px solid #eee;
        border-radius: 50%;
        overflow: hidden;
        cursor: pointer;
        margin: 0 auto;
    }

    .user-info-head:hover:after {
        content: '\e681';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        color: #fff;
        background-color: rgba(0, 0, 0, 0.3);
        font-size: 28px;
        padding-top: 2px;
        font-style: normal;
        font-family: layui-icon;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    .user-info-head img {
        width: 110px;
        height: 110px;
    }

    .user-info-list-item {
        position: relative;
        padding-bottom: 8px;
    }

    .user-info-list-item > .layui-icon {
        position: absolute;
    }

    .user-info-list-item > p {
        padding-left: 30px;
    }

    .layui-line-dash {
        border-bottom: 1px dashed #ccc;
        margin: 15px 0;
    }

    /* 基本信息 */
    #userInfoForm .layui-form-item {
        margin-bottom: 25px;
    }

    /* 账号绑定 */
    .user-bd-list-item {
        padding: 14px 60px 14px 10px;
        border-bottom: 1px solid #e8e8e8;
        position: relative;
    }

    .user-bd-list-item .user-bd-list-lable {
        color: #333;
        margin-bottom: 4px;
    }

    .user-bd-list-item .user-bd-list-oper {
        position: absolute;
        top: 50%;
        right: 10px;
        margin-top: -8px;
        cursor: pointer;
    }

    .user-bd-list-item .user-bd-list-img {
        width: 48px;
        height: 48px;
        line-height: 48px;
        position: absolute;
        top: 50%;
        left: 10px;
        margin-top: -24px;
    }

    .user-bd-list-item .user-bd-list-img + .user-bd-list-content {
        margin-left: 68px;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-sm4 layui-col-md4">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 25px;">
                    <form class="layui-form" id="userInfoForm" lay-filter="userInfoForm"
                          style="max-width: 400px;padding: 25px 10px 0 0;">
                        <div class="layui-form-item">
                            <div class="text-center layui-text">
                                <div class="user-info-head" id="userInfoHead">
                                    {{if eq .Data.userModel.AvatarUrl ""}}
                                    <img src="/resource/layadmin/assets/images/head.jpg" alt=""/>
                                    {{else}}
                                    <img src="/resource/{{.Data.userModel.AvatarUrl}}" alt=""/>
                                    {{end}}
                                </div>
                                <h2 style="padding-top: 20px;">{{.Data.userModel.Username}}</h2>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label layui-form-required">手机号:</label>
                            <div class="layui-input-block">
                                <input name="phone" value="{{.Data.userModel.Phone}}" class="layui-input"
                                       lay-verify="required" required/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label layui-form-required">邮箱:</label>
                            <div class="layui-input-block">
                                <input name="email" value="{{.Data.userModel.Email}}" class="layui-input"
                                       lay-verify="required" required/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label layui-form-required">姓名:</label>
                            <div class="layui-input-block">
                                <input name="real_name" value="{{.Data.userModel.RealName}}" class="layui-input"
                                       lay-verify="required" required/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">个人简介:</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="个人简介" class="layui-textarea">{{.Data.userModel.Remark}}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" type="button" lay-filter="userInfoSubmit" lay-submit>更新基本信息
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'form', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var _avatarUrlData = "";

        /* 选择头像 */
        $('#userInfoHead').click(function () {
            let _url = "{{.Data.userModel.AvatarUrl}}";
            if (_url !== "") {
                _url = '/resource/' + _url
            }
            admin.cropImg({
                imgSrc: _url,
                onCrop: function (res) {
                    _avatarUrlData = res;
                    $('#userInfoHead>img').attr('src', res);
                }
            });
        });

        /* 监听表单提交 */
        form.on('submit(userInfoSubmit)', function (data) {
            let _data = data.field;
            _data.is_update_avatar = false;
            _data.avatar_url = _avatarUrlData;
            if (_avatarUrlData !== "") {
                _data.is_update_avatar = true;
            }
            let _load = layer.load(2);
            admin.req('/admin/user/info', _data, function (data) {
                layer.close(_load);
                if (data.code === 0) {
                    layer.msg("更新成功！", {icon: 1}, function () {
                        top.window.location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            }, 'post');
            return false;
        });

    });
</script>